/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.model.Command.EditCommand;

import java.awt.Color;
import javax.swing.JOptionPane;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.Command.Command;
import simplemetrosystem.model.Element.MetroLine;
import simplemetrosystem.model.charlanguage.NameMap;

/**
 *
 * @author Eric Qian
 */
public class AddLineCommand implements Command {

    /**
     * 
     * @param name 
     */
    public AddLineCommand(String name) {
        success = false;
        nameMap = NameMap.getInstance();
        this.name = name;
    }

    public void execute() {
        ElementManager manager = ElementManager.getInstance();
        if (manager.addLine(name, name, MetroLine.STATUS_METRO, Color.WHITE)) {
            success = true;
            line = manager.findLine(name);
        } else {
            JOptionPane.showMessageDialog(null, nameMap.getName("Fail to add line"),
                    nameMap.getName("WARNING"), JOptionPane.WARNING_MESSAGE);
        }
    }

    public void undo() {
        if (success) {
            ElementManager.getInstance().removeLine(line);
        }
    }
    private NameMap nameMap;
    private boolean success;
    private String name;
    private MetroLine line;
}
